﻿using System;
using EPiServer;
using EPiServer.Core;

namespace EPiBoost.Core.Extensions
{
    public static class PageReferenceExtensions
    {
        public static PageData GetPage(this PageReference pageReference)
        {
			if (!PageReference.IsNullOrEmpty(pageReference))
			{
				return EPiServer.DataFactory.Instance.GetPage(pageReference);
			}
        	return null;
        }
        
        public static T GetPage<T>(this PageReference pageReference) where T : PageData
        {
			if (!PageReference.IsNullOrEmpty(pageReference))
			{
				return EPiServer.DataFactory.Instance.Get<T>(pageReference);
			}
        	return default(T);
        }

		#region Url

		/// <summary>
		/// Get the external URL for a page
		/// </summary> 
		public static string GetExternalUrl(this PageReference pageReference)
		{
			return pageReference.GetPage().GetExternalUrl();
		}


		#endregion
		 
	}
}
